package com.chen.admin.service;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chen.admin.common.Result;
import com.chen.admin.entity.Finance;
import com.chen.admin.mapper.FinanceMapper;
import com.chen.admin.mapper.HotelRoomMapper;
import com.chen.admin.mapper.RoomFinanceIdMapper;
import com.chen.admin.response.FinanceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class FinanceService {


    @Autowired
    private FinanceMapper financeMapper;
    @Autowired
    private RoomFinanceIdMapper roomFinanceIdMapper;
    @Autowired
    private HotelRoomMapper hotelRoomMapper;
    public List<FinanceResponse> getFinanceAcount() {

        /**
         * 先进行销售额的计算
         */
           //通过roomId查询到对应的酒店房间号
//      int hotelRoomId=  roomFinanceIdMapper.getRoomFinanceId(roomId);
//      //根据hotel_room_id 查询对应房间的价格
//        int price=hotelRoomMapper.getPrice(hotelRoomId);
//        //计算入住天数
//        Finance finance = financeMapper.selectById(roomId);
//        Date checkInDate = finance.getCheckInDate();
//        Date checkOutDate = finance.getCheckOutDate();
//        long days=(checkOutDate.getTime()-checkInDate.getTime())/(1000*60*60*24);
//        //计算价格
//        long account = days * price;
//        FinanceResponse financeResponse = new FinanceResponse();
//        financeResponse.setRoomId(roomId);
//        financeResponse.setTotalAmount(account);
//        return Result.success(financeResponse);

        List<Finance> finances = financeMapper.selectList(new LambdaQueryWrapper<>());
        FinanceResponse financeResponse = new FinanceResponse();
        ArrayList<FinanceResponse> objects = new ArrayList<>();
        for (Finance finance : finances) {
            financeResponse.setId(finance.getId());
            financeResponse.setRoomId(finance.getRoomId());
          financeResponse.setTotalAmount(finance.getTotalAmount());
          objects.add(financeResponse);
        }
        return objects;

    }
}
